﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HRM.Common;
using System.Data;

namespace HRM.Controller
{
    public class SalaryFund_Controller : Standard_Controller
    {
        #region "Contructor"
        private static SalaryFund_Controller _instance;
        protected SalaryFund_Controller() { }
        protected void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static SalaryFund_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new SalaryFund_Controller();
                }
            }
            return _instance;
        }
        public static SalaryFund_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                SalaryFund_Controller _instanceTrans = new SalaryFund_Controller();
                _instanceTrans.Trans_Name = transName;
                return _instanceTrans;
            }
            else
                return Instance();
        }
        #endregion


        public DateTime GetMaxKyPS(string sBranchCode)
        {
            string sQuery = "SELECT '01' + '/' + right(('00' + CAST(MONTH(MAX(SalaryFund_Month)) as varchar)),2) + '/' + CAST(YEAR(MAX(SalaryFund_Month)) as varchar)  FROM HRM_SalaryFund WHERE SalaryFund_BranchCode='" + sBranchCode + "'";
            object obj = DataConnect.ExecuteScalar(DataConnect.WorkingConnect,CommandType.Text,sQuery);
            return obj != null ? DateTime.ParseExact(obj.ToString(),"dd/MM/yyyy",null) : DateTime.MinValue;
        }

    }
}
